$(document).ready(function(){
    $('.msg-box>ul li').click(function(){
        $(this).addClass('active').siblings('li').removeClass('active');
        if($(this).hasClass('tab1')){
            $('.service-message').removeClass('hide').siblings('div').addClass('hide');
        }else if($(this).hasClass('tab2')){
            $('.leave-message').removeClass('hide').siblings('div').addClass('hide');
        }
    });
    $('.msg-box').on('click','.leave-message .msg-item',function(){
    	var id = $(this).attr('data-id');
    	window.location.href = "/DistributorSystem/message/updateMessage?id="+id;
    }) 
    $('.msg-list').on('click','.msg-item s',function(e){
    	e.stopPropagation();
    	var id=$(this).parent('div.msg-item').attr('data-id');
    	window.location.href = "/DistributorSystem/message/deleteMessageFromIndex?id="+id;
    });
  //退出
    $('.profine .my').on('click','p',function(){
    	if($(this).html()=='我的账号'){
    		
    	}else if($(this).html()=='修改密码'){
    		
    	}else if($(this).html()=='退出'){
    		window.location.href = "/DistributorSystem/distributorUser/quitLogin";
    	}
    });
    //表格单选/全选
    $('table').on('click','s',function(){
        $(this).toggleClass('selected');
    });
    $("table").on('click','tbody s',function (e) {
        e.stopPropagation();
        var item = $(this).parent().parent().parent().find('s');
        var count = 0;
        $(item).each(function () {
            if (!$(this).hasClass('selected')) {
                $(this).removeClass('selected');
                return false;
            } else {
                count++;
            }
        });
        if (count == item.length) {
            $(this).parent().parent().parent().siblings('thead').find('s').addClass('selected');
        } else {
            $(this).parent().parent().parent().siblings('thead').find('s').removeClass('selected');
        }
    });
    $("table").on('click','thead s',function (e) {
        e.stopPropagation();
        if(!$(this).hasClass('selected')){
            $('table tbody s').removeClass('selected');
        }else{
            $('table tbody s').addClass('selected');
        }
    });
});
//字符串非空验证
function trim(s){
    return s.replace(/(^\s*)|(\s*$)/g, "");
};
//提示框
function promtp(msg){
	layer.msg(msg, {
		  time: 1500,
		  area: '300px',
		  icon:2,
		  offset: '0'
		});
}
/*获取页面地址的参数*/
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
    var r = window.location.search.substr(1).match(reg);
    if (r!=null) return (r[2]); return null;
}
//将数字转换为人民币格式
function cc(s){
    if(/[^0-9\.]/.test(s)) return "invalid value";
    s=s.replace(/^(\d*)$/,"$1.");
    s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
    s=s.replace(".",",");
    var re=/(\d)(\d{3},)/;
    while(re.test(s))
        s=s.replace(re,"$1,$2");
    s=s.replace(/,(\d\d)$/,".$1");
    return "￥" + s.replace(/^\./,"0.")
}
//日期格式化
Date.prototype.format = function(fmt) { 
    var o = { 
       "M+" : this.getMonth()+1,                 //月份 
       "d+" : this.getDate(),                    //日 
       "h+" : this.getHours(),                   //小时 
       "m+" : this.getMinutes(),                 //分 
       "s+" : this.getSeconds(),                 //秒 
       "q+" : Math.floor((this.getMonth()+3)/3), //季度 
       "S"  : this.getMilliseconds()             //毫秒 
   }; 
   if(/(y+)/.test(fmt)) {
           fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
   }
    for(var k in o) {
       if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
   return fmt; 
}  
